/*
 * @Description:
 * @Author: maskMan
 * @LastEditTime: 2024-03-02 14:50:54
 */
import { MARK } from '../define/variable'
const { ccclass, property } = cc._decorator
@ccclass
export class Tips extends cc.Component {
  @property(cc.Label)
  text_label: cc.Label = null
  @property(cc.Label)
  time_label: cc.Label = null
  tipTxt: string = ''
  timeValue = 10
  canClose = false
  canShowTime: boolean = false
  isOpactiy = false
  start() {
    try {
      if (this.isOpactiy) {
        this.node.getChildByName('bg').opacity = 0
        this.node.getComponent(cc.BlockInputEvents).enabled = false
      } else {
        this.node.getChildByName('bg').opacity = 180
      }
      this.text_label.string = this.tipTxt
      if (this.canClose) {
        this.node.on(cc.Node.EventType.TOUCH_END, () => {
          this.destroy()
        })
      }
      //显示倒计时
      if (this.canShowTime) {
        let count = this.timeValue
        this.time_label.string = count.toString()
        this.schedule(() => {
          count--
          if (count < 0) {
            this.destroy()
          }
          this.time_label.string = count.toString()
        }, 1)
      } else {
        this.scheduleOnce(() => {
          this.destroy()
        }, 1 * this.timeValue)
      }
    } catch (error) {
      console.log('error: ', error)
    }
  }
  onDestroy() {
    this.node.emit(MARK.NODE_EVENT)
    this.node.destroy()
  }
}
